const express = require('express')
const bodyParser = require('body-parser')
const cookieParser = require('cookie-parser')

const app = express()

app.use(bodyParser.urlencoded({extended: true}))
app.use(cookieParser())

app.get('/api/cors', function(req, res) {
  res.header('Access-Control-Allow-Credentials', true) // 后端允许发送cookie信息
  res.header('Access-Control-Allow-Origin', 'http://www.cross.com:3000') // 允许访问的域名
  res.cookie('cors-status', false, {domain: 'cross.com', maxAge: 100000, httpOnly: true})
  res.send({data: '5000端口发来贺电'})
})

app.listen(5000, function(req, res) {
  console.log("5000端口服务器也打开，可以访问接口")
})